<?php
/**
 * User:chendenan
 * Created On 2022/3/13 0013 19:26
 */

namespace app\common\lib;
class ClassArr {
    public static function smsClassStat(){
        return [
            "ali"=>"app\common\lib\sms\AliSms",
            "baidu"=>"app\common\lib\sms\BaiduSms",
            "jd"=>"app\common\lib\sms\JdSms",
            "dxw"=>"app\common\lib\sms\DxwSms",
        ];
    }
    public static function uploadClassStat(){
        return [
            "text" => "xx",
            "image" => "xxx",
        ];
    }
    public static function initClass($type,$classs,$args=[],$needInstance=false){
        //如果我们工厂模式调用的是静态方法，那么我们这个地方返回的是静态类库 如：AliSms
        //如果不是静态的，我们需要返回对象
        if(!array_key_exists($type,$classs)){
            //return false;
            throw new \Exception("类型：{$type}的类库找不到");
        }
        $className = $classs[$type];
        //反射机制 new ReflectionClass('AliSms') => 建立AliSms反射类
        // -> newInstanceArgs($args)  => 相当于实例化AliSms 对象
        //return $needInstance == true ? (new \ReflectionClass($className) )->newInstanceArgs($args) : $className ;
        return (new \ReflectionClass($className) )->newInstanceArgs($args);
    }
}